package logic

import (
	"context"
	"nove/models/mysql"

	"nove/noverpc/internal/svc"
	"nove/noverpc/noverpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CollectListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectListLogic {
	return &CollectListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CollectListLogic) CollectList(in *noverpc.CollectListRequest) (*noverpc.CollectListResponse, error) {
	// todo: add your logic here and delete this line

	var collect []mysql.CollectData
	mysql.DB.Debug().Model(&mysql.Collect{}).Select("collects.*,users.nike_name,books.title").
		Joins("left join users on users.nike_name=collects.user_id").
		Joins("left join books on books.title=collects.book_id").
		Where("collects.id=?", in.CollectId).Find(&collect)
	var collectList []*noverpc.CollectList
	for _, bo := range collect {
		list := noverpc.CollectList{
			NikeName: bo.NikeName,
			Title:    bo.Title,
		}
		collectList = append(collectList, &list)
	}
	return &noverpc.CollectListResponse{
		List: collectList,
	}, nil
}
